package com.suixinsanren.design.state.demo.demo06;

public class SoldOutState implements State {

    private final GumballMachine gumballMachine;

    public SoldOutState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("糖果已售罄，投币没用");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("没有投入硬币，无法退还");
    }

    @Override
    public void turnCrank() {
        System.out.println("没有投入硬币，无法开始游戏");
    }

    @Override
    public void refill(int numberGumball) {
        gumballMachine.setCount(numberGumball);
        if (gumballMachine.getCount() > 0) {
            System.out.println("补充了" + numberGumball + "颗糖果");
            gumballMachine.setState(gumballMachine.getNoQuarterState());
        }
    }

    @Override
    public String toString() {
        return "糖果已售罄";
    }
}
